
package com.hyst.common;

import java.util.ArrayList;
import java.util.List;

import com.github.pagehelper.Page;

import lombok.Data;

/**
 * @Description:
 * @Date：2017年12月6日 @author： DongY
 * @version ：1.0 1.[2017年12月6日]CreatBy：dy
 */
@Data
public class ResultPage<T> implements ResultAble<T> {

	private static final long serialVersionUID = 1L;

	public static final int DEFAULT_SIZE = 10;

	public static final int DEFAULT_PAGE_NUM = 1;

	private List<T> rows;

	private int pageSize = DEFAULT_SIZE;

	private int pageNum = DEFAULT_PAGE_NUM;

	private long total = 1L;

	private int code = SUCCESS;

	private String msg = "success";

	public static <T> ResultPage<T> success(final Page<T> datas) {
		return new ResultPage<>(datas);
	}

	public static <T> ResultPage<T> fail(final String errMsg,int errCode) {
		return new ResultPage<>(errMsg,errCode);
	}
	// public static <T> ResultPage<T> success(final List<T> datas) {
	// return new ResultPage<>(datas);
	// }

	private ResultPage(final Page<T> datas) {
		pageNum = datas.getPageNum();
		pageSize = datas.getPageSize();
		total = datas.getTotal();
		rows = datas.getResult();
	}

	private ResultPage(String errMsg,int errCode) {
		total = 0;
		rows = new ArrayList<T>();
		code = errCode;
		msg = errMsg;
	}

	private ResultPage() {

	}
}
